package com.tudouji.project.handover.controller;

import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.handover.domain.CustomerVo;
import com.tudouji.project.handover.service.CustomerVoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作交接客户展示
 */
@RestController
@RequestMapping("/customer/vo")
public class CustomerVoController extends BaseController {

    @Autowired
    private CustomerVoService customerVoService;


    /**
     * 查询客户列表
     *
     * @param
     * @return
     */
//    @PreAuthorize("@ss.hisPermi('customer:vo:list')")
    @GetMapping("list")
    public TableDataInfo list( CustomerVo customerVo) {
        startPage();
        List<CustomerVo> list = customerVoService.selectCustomerVoList(customerVo);
        return getDataTable(list);
    }

    /**
     * 根据客户guid查询部门关系
     * @param guid
     * @return
     */
    @GetMapping(value = "/{guid}")
    public AjaxResult selectCustomerVoByGuid(@PathVariable("guid") String guid){
        List<CustomerVo> customerVo=customerVoService.selectCustomerVoByGuid(guid);
        return AjaxResult.success(customerVo);
    }

    /**
     * 根据用户id查询客户信息
     * @param
     * @return
     */
    @GetMapping("")
    public AjaxResult selectCustomerVoByUserid(Long userId,String customerid){
        List<CustomerVo> customerVoList=customerVoService.selectCustomerVoByUserid(userId,customerid);
        return AjaxResult.success(customerVoList);
    }

    /**
     * 移交客户交接单
     *
     * @param fromUserId
     * @return
     */
    @PostMapping("update")
    public AjaxResult updateCustomerVo(Long fromUserId,Long toUserId,String[] guid,String picked) {
        return customerVoService.updateCustomerVo(fromUserId,toUserId,guid,picked);
    }

    /**
     * 修改部门用户关系
     * @param
     * @return
     */
    @PutMapping("")
    public AjaxResult updateCustomerVoSeller(CustomerVo customerVo){
        return AjaxResult.success(customerVoService.updateCustomerVoSeller(customerVo));
    }

    /**
     * 新增客户经理关系
     * @param customerVo
     * @return
     */
    @PostMapping("")
    public AjaxResult insertCustomerVo(CustomerVo customerVo){
        return AjaxResult.success(customerVoService.insertCustomerVo(customerVo));
    }


}
